package service.custom.impl;

import java.util.List;

import model.credit.Lcbank;

import dao.LcBankDao;
import exception.Exceptions;

import service.custom.CustomLcBankInforService;

public class CustomLcBankInforServiceImpl implements CustomLcBankInforService {
	private LcBankDao lcBankDao;

	@Override
	public void save(Integer cid, Integer comid, List<String> basicbank,
			List<String> basicdepositbank, int type) {
		if (basicbank != null && basicdepositbank != null) {
			int sizeL = (basicbank.size() > basicdepositbank.size() ? basicbank
					.size() : basicdepositbank.size());
			for (int i = 0; i < sizeL; i++) {
				if (basicbank.get(i).equals("") && basicdepositbank.get(i).equals("")) {
					continue;
				}
				Lcbank lcBank = new Lcbank();
				lcBank.setCid(cid);
				lcBank.setBankname(basicbank.get(i));
				lcBank.setSaveaccount(basicdepositbank.get(i));
				lcBank.setType(type);
				lcBank.setComid(comid);
				lcBankDao.save(lcBank);
			}
		}
	}

	@Override
	public void delete(Integer cid, Integer comid, int type) throws Exceptions {
		List<Lcbank> lcBankList = this.lcBankDao.findModel("cid = " + cid
				+ " and comid = " + comid + " and type = " + type);
		if (lcBankList != null) {
			for (Lcbank lc : lcBankList) {
				try {
					this.lcBankDao.delete(lc);
				} catch (Exception e) {
					throw new Exceptions("处理银行账号时出现异常，请联系开发人员！");
				}
			}
		}
	}

	public LcBankDao getLcBankDao() {
		return lcBankDao;
	}

	public void setLcBankDao(LcBankDao lcBankDao) {
		this.lcBankDao = lcBankDao;
	}

	@Override
	public List<Lcbank> findList(Integer cid, Integer comid, int type)
			throws Exceptions {
		return this.lcBankDao.findModel("cid = " + cid + " and comid = "
				+ comid + " and type = " + type);
	}

}
